<?php
	/*----------------------------------------------------------------
	*
	* Xu ly hien thi cac items
	*
	-----------------------------------------------------------------*/
	$type = 0;
	$typename="";
	$newsContent = "";
	$productContent="";
	$maincontent = "<br/><br/>";
	$count=0;
	if(!isset($_GET['jmp']))
	{
		$curAdd =  $_SERVER['PHP_SELF'];
		if(strstr($curAdd,"productsajx.php") !=""&&isset($_GET['view'])&&$_GET['view']=="new")
		{
			$cType = new CType ;
			
			$arrType = $cType ->CTypeList();
			
			
			
			if(is_array($arrType) && !is_numeric($arrType))
			{
				$maincontent .= "<div><style>.DLBodyLight{background:#666}</style>";
				$typename ="New Products";
				foreach ($arrType as $keyType => $valueType)
				{
					$cItems = new CItems ; 
					$arrItems = $cItems -> CItemListOfTypeLimited ($valueType['id'],8);
					
					
					$numOfItems = count ($arrItems);
					
										
					if(is_array($arrItems) && !is_numeric($arrItems))
					{
						$maincontent .='<div class="DLNewProHeader"><h1><i>'.$valueType['name'].'</i>&nbsp;<img src="images/icon_new.gif"/></h1></div><br/>';
						$maincontent .= "<table width='100%' class='DLNewPro' cellspacing='10' border='0' style='margin-bottom: 10px;' id='newprotb'> ";
									
				
						$width4SubTable = 600/4;
						
						//echo $width4SubTable;
						//foreach ($arrItems as $key=>$value)
						
						foreach($arrItems as $keyItem=>$valueItem)
						{
							if($count ==0 )
							{
								$maincontent .="<tr>";
							}
							
							$count++;
							$maincontent.="<td  align='center'>".$cItems -> CItemsPackOfBlock($valueItem,$perform_sytle,$width4SubTable)."</td>";				
							
							if($count == 4)
							{
								$maincontent .="</tr>";
								$count =0;
							}
						}
						$col_remaining = 4 - $count;
						
						if($count >0 && $count < 4)
						{
							for ($i = 0 ; $i< $col_remaining ; $i++)
								$maincontent.="<td width='".$width4SubTable."px'></td>";
							$maincontent .="</tr>";
						}
						
						$maincontent .="</table>";
					}					
					
				}
				
				//$maincontent.='</td></tr></table>';
				$maincontent.='</div>';
				
			}
			else
			{
				$maincontent ="Updating data of types for new products....! Please come back later";
			}
		}
		
		if( strstr($curAdd,"productsajx.php") !=""&&!isset($_GET['view']))
		{
			$cType = new CType;
			$arrType = $cType->CTypeList();
			
			if(is_array($arrType) && !is_numeric($arrType))
			{
				$typename ="Products";
				
				$maincontent .= "<table width='100%' class='my_command_body2' cellspacing='0' border='0' style='margin-bottom: 10px;'> ";
				
				foreach ($arrType as $keyType =>$valueType)
				{
					$maincontent .='<tr>';
					$maincontent .='<td class="DLProductDetailHead" valign="top"> &nbsp;&nbsp;&nbsp;&nbsp;<h1>'. $valueType['name'].'</h1></td></tr><tr>';
					$maincontent .='<td  class="DLProductDetailDes"><i>'. $valueType['description'].'</i></td></tr><tr>';
					$maincontent .='<td align="right"><br/>View <u><a href="products.php?jmp=idb'.$valueType['id'].'&to='.$valueType['name'].'"><font color="#cc0000">all items </font></a></u> of '. $valueType['name'].'<br/><br/></td>';
					$maincontent .='</tr>';
				}
					
				
				
				
				$maincontent .='</table>';
			}
			else
			{
				$maincontent ="Updating data of types ....! Please come back later";
			}		
			
		}
		//************************************************				
		//start news				
		//************************************************
		/*
		
		
		$cNews = new CArticles;
		
		
		
		$arrNews = $cNews->CArticlesList(4);
		$welcome = $cNews -> CArticlesDetail(1);
		if(is_array($arrNews))
		{
			$typename="";//$welcome['title'];
			
					
							
		$maincontent .="<hr/>	
							<table class='my_command_body2' cellspacing='10' border='0' style='margin-bottom: 10px; width='100%'> 				
								<tr>
									<td height='30px' colspan='2' bgcolor='#AB3032'>
										<h2>
											News
										</h2>
									</td>
								</tr>
								<tr>
									<td width='60%'>
										<table width='100%' class='my_command_body' cellspacing='10' border='0' style='margin-bottom: 10px;'> ";
			foreach ($arrNews as $key=>$value)
			{
			$maincontent.="			<tr>
										<td>	<img src='".$value['picture']."'> 
										</td>
										<td>
											<h3>".$value['title']."</h3>
											<br>
											".substr( $value['content'],0,120)." .... <a href = '#'> View more </a>
											<br>
											".$value['source']."	
											<br>
											".$value['dateposted']."
										</td> 
									</tr> 
									<tr>
										<!--<td colspan='2'> <hr> 
										</td> -->
									</tr>";
			}
			
			//table3 la cac tin tuc lien quan khac
			$maincontent.=	"	</table>
							</td>
							<td valign='top' align='left'>
								<table width='100%' class='my_command_body' cellspacing='10' border='0' style='margin-bottom: 10px;'>
									<tr>
										<td bgcolor='#AB2928' height='20px'>
											Other News
										</td>
									</tr>
									<tr>
										<td>
											Chua co tin tuc nao moi trong CSDL
										</td>
									</tr>
								</table>	
							</td>
						</tr>
					</table>
					<hr/>";			
			
			
		}
		
		$maincontent .="<table width='100%' class='my_command_body2' cellspacing='10' border='0' style='margin-bottom: 10px; width='100%'> 				
								<tr>
									<td height='30px' bgcolor='#AB3032'>
										<h2>
											New Products
										</h2>
									</td>
								</tr>
								<tr>
									<td>
										asdfadsf
									</td>
								</tr>
						</table>		"; */
						
		//************************************************				
		//end news				
		//************************************************
	}
	
	
	//else: co bien jmp dc request
	else
	{
		$id = substr($_GET['jmp'], 3);
		$typename = $_GET['to'];	
		$cItems = new CItems;
		$cType=new Ctype;
		$pager = new Pager;
		//$pager->event=' onclick="javascript:alert(\'ok\')" ';
		$itemType=$cType->CTypeDetail ($id);
		
		// 2 bien col_limit va` perform_style dc khai bao trong file config do nha
		if(!isset($_GET['with']))
		{
		
			
			$arrItems = $cItems->CItemsListOfType($id);
		
		
			$numOfRecord = count ($arrItems);
			
			$start = $pager->findStart($pager_limit);
			$end = min($numOfRecord , $start + $pager_limit);
			
			$pages = $pager->findPages($numOfRecord , $pager_limit);
			if(!isset ($_GET['page']))
			{
				$_GET['page'] = 1; 
			}	
				
			$pagelist = $pager->PageList($_GET['page'], $pages,' onclick="javascript:ajaxLoad(\'main\',this.href);return false" ');
		
			if(is_array($arrItems))
			{
				$maincontent = "<table width='100%' class='my_command_body2' cellspacing='10' border='0' style='margin-bottom: 10px;'> ";
									
				
				$width4SubTable = 610/$col_limit;
				
				//echo $width4SubTable;
				//foreach ($arrItems as $key=>$value)
				
				for($i=$start; $i<$end; $i++)
				{
					if($count ==0 )
					{
						$maincontent .="<tr>";
					}
					
					$count++;
					$maincontent.="<td  align='center'>".$cItems -> CItemsPackOfBlock($arrItems[$i],$perform_sytle,$width4SubTable)."</td>";				
					
					if($count == $col_limit)
					{
						$maincontent .="</tr>";
						$count =0;
					}
				}
				$col_remaining = $col_limit - $count;
				
				if($count >0 && $count <$col_limit)
				{
					for ($i = 0 ; $i< $col_remaining ; $i++)
						$maincontent.="<td width='".$width4SubTable."px'></td>";
					$maincontent .="</tr>";
				}
				
				if($pages>1)		
					$maincontent .="<tr><td align='right' colspan='".$col_limit."'>". $pagelist. "</td></tr></table>";
				else
					$maincontent .="</table>";
			}
			if($numOfRecord  ==0)
			{
				$maincontent ="There are not any products of this type. Please come back later";
			}
		}
		//else nguoc lai co bien with dc request
		else
		{
			$with = $_GET['with'];
				//CO SAN PHAM DC REQUEST
			$detailItems = $cItems->CItemsDetail($id);
		
			if(is_array($detailItems))
			{
				$maincontent = "<div class='DLItemDetail'> ";
									
								
				
				//foreach ($detailItems as $key=>$value)
				//{
					$count++;
					$maincontent.="<img class='DLImgDetail' src='./applications/resources/".$detailItems['picture']."'>";
					$maincontent .= "<div style='float:left;padding:20px;'>";
					$maincontent.="<font size='4'><b>Product Details</b></font><br/></br>";
					$maincontent.="<table width='100%' border='0' style='font-size:13px;'>";				
					$maincontent.="<tr><td style='padding-right:20px;height:20px'>".constant("P_NAME")."</td><td><b>".$detailItems['name']."</b></td></tr>";
					$maincontent.="<tr><td style='padding-right:20px;height:20px'>".constant("P_ID")."</td><td><b>".$detailItems['id_items']."</b></td></tr>";
					$maincontent.="<tr><td style='padding-right:20px;height:20px'>".constant("P_MANUFACTURER")."</td><td>".$detailItems['manufacture']."</td></tr>";
					$maincontent.="<tr><td style='padding-right:20px;height:20px'colspan='2'><u><i>Description:</i></u></td></tr>";
					$maincontent.="<tr><td colspan='2' style='font-size:12px;font-weight:normal;border:1px #999 solid;padding:10px' width='100%'>".$detailItems['description']."</td></tr>";
					//$maincontent.=$detailItems['price']."<br/>";
					$maincontent.="</table>";
					$maincontent .= "</div>";		
					
				//}
						
				$maincontent .="<div style='clear:both'></div></div>";
			}
			if($count ==0)
			{
				$maincontent ="There are not any products of this type. Please come back later";
			}		
			
		}
	}
/*	else
	{
		
	}*/




?>


